home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 102_01.zip / PACMAN.C < prev    next >
Text File  |  1993-06-03  |  6KB  |  316 lines

  1. /*
  2.  * PACMAN  - written by Dave Nixon, AGS Computers Inc., July, 1981.
  3.  *
  4. */
  5.  
  6. #include    "pacdefs.h"
  7.  
  8. main(argc, argv)
  9.  char **argv;
  10. {
  11.     int tmp;        /* temp variables */
  12.     int pac_cnt;
  13.     int monstcnt;    /* monster number */
  14.     struct pac *mptr;
  15.     char gcnt[10];
  16.  
  17.     UpdSc = 0;        /* haven't updated score file yet */
  18.     rawio();
  19.     gscore();        /* read in score file */
  20.     if (!setjmp(jbuf))
  21.         instruct();    /* instructions first time only */
  22.     init(argc, argv);        /* global init */
  23.     for (pac_cnt = MAXPAC; pac_cnt > 0; pac_cnt--)
  24.     {
  25. redraw:
  26.         clr();
  27.         SPLOT(0, 45, "SCORE: ");
  28.         SPLOT(21, 45, "gold left = ");
  29.         POS(21, 57); printf("%6d", goldcnt);
  30.  
  31.         if (potion == TRUE)
  32.         {
  33.             SPLOT(3, 45, "COUNTDOWN: ");
  34.         };
  35.         pacsymb = PACMAN;
  36.         killflg = FALSE;
  37.         POS(22, 45); printf("delay = %6d", delay);
  38.  
  39.         /*
  40.          * PLOT maze
  41.          */
  42.         for (tmp = 0; tmp < BRDY; tmp++)
  43.         {
  44.             SPLOT(tmp, 0, &(display[tmp][0]));
  45.         };
  46.  
  47.         /* initialize a pacman */
  48.  
  49.         Pac.xpos = pacstart.xpos;    Pac.ypos = pacstart.ypos;
  50.         Pac.dirn = pacstart.dirn;    Pac.speed = pacstart.speed;
  51.         Pac.danger = pacstart.danger;    Pac.stat = pacstart.stat;
  52.  
  53.         PLOT(pacptr->ypos, pacptr->xpos, pacsymb);
  54.         /* display remaining pacmen */
  55.         for (tmp = 0; tmp < pac_cnt - 1; tmp++)
  56.         {
  57.             PLOT(23, (MAXPAC * tmp), PACMAN);
  58.         };
  59.         /*
  60.          * Init. monsters
  61.           */
  62.         for (mptr = &monst[0], monstcnt = 0; monstcnt < MAXMONSTER; mptr++, monstcnt++)
  63.         {
  64.             mptr->xpos = MSTARTX + (2 * monstcnt);
  65.             mptr->ypos = MSTARTY;
  66.             mptr->speed = SLOW;
  67.             mptr->dirn = DNULL;
  68.             mptr->danger = FALSE;
  69.             mptr->stat = START;
  70.             PLOT(mptr->ypos, mptr->xpos, MONSTER);
  71.         };
  72.         rounds = 0;    /* timing mechanism */
  73.  
  74.         /* main game loop */
  75.         do
  76.         {
  77.             if (rounds++ % MSTARTINTVL == 0)
  78.             {
  79.                 startmonst();
  80.             };
  81.             pacman();
  82.             if (killflg == TURKEY)
  83.                 break;
  84.             for (monstcnt = 0; monstcnt < (MAXMONSTER / 2); monstcnt++)
  85.             {
  86.                 monster(monstcnt);    /* next monster */
  87.             };
  88.             if (killflg == TURKEY)
  89.                 break;
  90.             if (pacptr->speed == FAST)
  91.             {
  92.                 pacman();
  93.                 if (killflg == TURKEY)
  94.                     break;
  95.             };
  96.             for (monstcnt = (MAXMONSTER / 2); monstcnt < MAXMONSTER; monstcnt++)
  97.             {
  98.                 monster(monstcnt);    /* next monster */
  99.             };
  100.             if (killflg == TURKEY)
  101.                 break;
  102.             if (potion == TRUE)
  103.             {
  104.                 POS(3, 60); printf("%2d%c", potioncnt,
  105.                     ((potioncnt < 5) ? BEEP : ' '));
  106.  
  107.                 if (potioncnt-- < 0)
  108.                 {
  109.                     SPLOT(3, 45,
  110.                       "                        ");
  111.                     potion = FALSE;
  112.                     pacptr->speed = SLOW;
  113.                     pacptr->danger = FALSE;
  114.                     for (monstcnt = 0; monstcnt < MAXMONSTER; monstcnt++)
  115.                     {
  116.                         monst[monstcnt].danger = TRUE;
  117.                     };
  118.                 };
  119.             };
  120.             update();    /* score display etc */
  121.             if (goldcnt <= 0)
  122.             {
  123.                 reinit();
  124.                 goto redraw;
  125.             };
  126.         } while (killflg != TURKEY);
  127.         SPLOT(5, 45, "YOU ARE BEING EATEN");
  128.         SPLOT(6, 45, "THIS TAKES ABOUT 2 SECONDS");
  129.         sleep(2);
  130.     };
  131.     SPLOT(8, 45, "THE MONSTERS ALWAYS TRIUMPH");
  132.     SPLOT(9, 45, "IN THE END!");
  133.     over();
  134. }
  135.  
  136. pacman()
  137. {
  138.     int sqtype;
  139.     int mcnt;
  140.     int tmpx, tmpy;
  141.     int deltat;
  142.     char dir, dir1, dir2;
  143.     struct pac *mptr;
  144.  
  145.     /* pause; wait for the player to hit a key */
  146.     for (deltat = delay; deltat > 0; deltat--);
  147.  
  148.     /* get instructions from player, but don't wait */
  149.     poll(0);
  150.  
  151.     /* remember current pacman position */
  152.     tmpx = pacptr->xpos;
  153.     tmpy = pacptr->ypos;
  154.  
  155.     /* "eat" any gold */
  156.     /* update display array to reflect what is on terminal */
  157.     display[tmpy][tmpx] = VACANT;
  158.  
  159.  
  160.     /* what next? */
  161.     dir1 = pacptr->dirn;    dir2 = pacptr->dirx;
  162. again:    dir = dir1; dir1 = dir2; dir2 = DNULL;
  163.     switch (dir)
  164.     {
  165.     case DUP:
  166.         pacsymb = PUP;
  167.         switch (sqtype = display[tmpy + UPINT][tmpx])
  168.         {
  169.         case GOLD:
  170.         case VACANT:
  171.         case CHOICE:
  172.         case POTION:
  173.         case TREASURE:
  174.             pacptr->dirx = dir;    /* remember last dir */
  175.  
  176.             /* erase where the pacman went */
  177.             PLOT(tmpy, tmpx, VACANT);
  178.             pacptr->ypos += UPINT;
  179.             break;
  180.  
  181.         default:
  182.             goto again;
  183.         };
  184.         break;
  185.     case DDOWN:
  186.         pacsymb = PDOWN;
  187.         switch (sqtype = display[tmpy + DOWNINT][tmpx])
  188.         {
  189.         case GOLD:
  190.         case VACANT:
  191.         case CHOICE:
  192.         case POTION:
  193.         case TREASURE:
  194.             pacptr->dirx = dir;    /* remember last dir */
  195.  
  196.             /* erase where the pacman went */
  197.             PLOT(tmpy, tmpx, VACANT);
  198.             pacptr->ypos += DOWNINT;
  199.             break;
  200.  
  201.         default:
  202.             goto again;
  203.         };
  204.         break;
  205.     case DLEFT:
  206.         if(tmpx == 0)
  207.         {
  208.             /* erase where the pacman went */
  209.             PLOT(tmpy, tmpx, VACANT);
  210.             pacptr->xpos = XWRAP;
  211.             sqtype = VACANT;
  212.             break;
  213.         };
  214.         pacsymb = PLEFT;
  215.         switch (sqtype = display[tmpy][tmpx + LEFTINT])
  216.             {
  217.         case GOLD:
  218.         case VACANT:
  219.         case CHOICE:
  220.         case POTION:
  221.         case TREASURE:
  222.  
  223.             pacptr->dirx = dir;    /* remember last dir */
  224.             /* erase where the pacman went */
  225.             PLOT(tmpy, tmpx, VACANT);
  226.             pacptr->xpos += LEFTINT;
  227.             break;
  228.         
  229.         default:
  230.             goto again;
  231.         };
  232.         break;
  233.     case DRIGHT:
  234.         if(tmpx == XWRAP)
  235.         {
  236.             /* erase where the pacman went */
  237.             PLOT(tmpy, tmpx, VACANT);
  238.             pacptr->xpos = 0;
  239.             sqtype = VACANT;
  240.             break;
  241.         };
  242.         pacsymb = PRIGHT;
  243.         switch (sqtype = display[tmpy][tmpx + RIGHTINT])
  244.         {
  245.         case GOLD:
  246.         case VACANT:
  247.         case CHOICE:
  248.         case POTION:
  249.         case TREASURE:
  250.  
  251.             pacptr->dirx = dir;    /* remember last dir */
  252.             /* erase where the pacman went */
  253.             PLOT(tmpy, tmpx, VACANT);
  254.             pacptr->xpos += RIGHTINT;
  255.             break;
  256.  
  257.         default:
  258.             goto again;
  259.         };
  260.         break;
  261.     };
  262.  
  263.     /* did the pacman get any points or eat a potion? */
  264.     switch (sqtype)
  265.     {
  266.     case CHOICE:
  267.     case GOLD:
  268.         pscore++;
  269.         goldcnt--;
  270.         break;
  271.  
  272.     case TREASURE:
  273.         pscore += TREASVAL;
  274.         break;
  275.  
  276.     case POTION:
  277.         SPLOT(3, 45, "COUNTDOWN: ");
  278.         potion = TRUE;
  279.         potioncnt = POTINTVL;
  280.         pacptr->speed = FAST;
  281.         pacptr->danger = TRUE;
  282.  
  283.         /* slow down monsters and make them harmless */
  284.         mptr = &monst[0];
  285.         for (mcnt = 0; mcnt < MAXMONSTER; mcnt++)
  286.         {
  287.             if (mptr->stat == RUN)
  288.             {
  289.                 mptr->speed = SLOW;
  290.                 mptr->danger = FALSE;
  291.             };
  292.             mptr++;
  293.         };
  294.         break;
  295.     };
  296.  
  297.     /* did the pacman run into a monster? */
  298.     for (mptr = &monst[0], mcnt = 0; mcnt < MAXMONSTER; mptr++, mcnt++)
  299.     {
  300.         if ((mptr->xpos == pacptr->xpos) &&
  301.             (mptr->ypos == pacptr->ypos))
  302.         {
  303.  
  304.             killflg = dokill(mcnt);
  305.         }
  306.         else
  307.         {
  308.             killflg = FALSE;
  309.         };
  310.     };
  311.     if (killflg != TURKEY)
  312.     {
  313.         PLOT(pacptr->ypos, pacptr->xpos, pacsymb);
  314.     };
  315. }
  316.